<?php
session_start();

if(!isset($_SESSION['last_key'])) {
  echo '{"error_code":0, "error":"Not logged in"}';
  return;
}

include_once('config.php');
include_once('weibooauth.php');

$c = new WeiboClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);

$user_id = isset($_GET['user_id']) && $_GET['user_id'] != 0 ? $_GET['user_id'] : $_SESSION['id']; // id or nick name
$page    = isset($_GET['page']) ? $_GET['page'] : WB_START_PAGE;
$count   = isset($_GET['count']) ? $_GET['count'] : WB_COUNT_EACH_PAGE;

$page -= 1;
$cursor = $page * $count;
$msg = $c->followers($cursor, $count, $user_id);

echo json_encode($msg);
?>